<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box{
            width: 100px;
            height: 100px;
            background: aquamarine;
            position: absolute;
            left: 0px;
        }
    </style>
</head>
<body>
    <div class="box"></div>
    <script>
        let box = document.querySelector('.box');
        //匀速运动
        /*
        let left = 0;
        box.onmouseover = function (){
            let timer = setInterval(() => {
                left += 13;
                if(left >= 1000){
                    left = 1000;
                    clearInterval(timer);
                }
                box.style.left = left + 'px';
            },100)
        }*/

        //加速运动
        /*let left = 0;
        let speed = 0;
        let timer = setInterval(()=>{
            speed += 8;
            left = left + speed;
            if(left >= 1000){
                left = 1000;
                clearInterval(timer);
            }
            box.style.left = left + 'px';
        },60)*/

        //减速运动
        /*let speed = 100;
        let left = 0;
        let timer = setInterval(()=>{
            speed -= 12;
            left = left +speed;
            if(speed <= 0){
                clearInterval(timer);
            }
            box.style.left = left + 'px';
        },120)*/

        //缓冲运动
        let speed = 0;
        let left = 0;
        let target = 623;
        let timer = setInterval(()=>{
            speed = Math.ceil((target - left) / 5);
            left = left + speed;
            if(left === target){
                clearInterval(timer);
            }
            box.style.left = left + 'px';
        },100)
    </script>
</body>
</html>